package com.llb666.shop.items.domain.service.center;

import com.llb666.common.core.utils.id.uuid.IdUtils;
import com.llb666.common.core.utils.page.PagedGridResult;
import com.llb666.shop.items.api.dto.OrderItemsCommentDto;
import com.llb666.shop.items.domain.client.OrderClient;
import com.llb666.shop.items.domain.entity.ItemsComments;
import com.llb666.shop.items.domain.entity.ItemsImg;
import com.llb666.shop.items.domain.entity.bo.MyCommentBo;
import com.llb666.shop.items.domain.repository.ItemsCommentsRepository;
import com.llb666.shop.items.domain.repository.ItemsImgRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

/**
 * 我的订单商品评论.
 *
 * @author llb666
 */
@Service
@RequiredArgsConstructor(onConstructor_ = {@Autowired})
public class MyCommentsService {

    private final ItemsCommentsRepository itemsCommentsRepository;
    private final OrderClient orderClient;

    public void saveComments(String orderId, String userId, List<OrderItemsCommentDto> commentList) {
        // 1. 保存评价 items_comments
        for (OrderItemsCommentDto oic : commentList) {
            oic.setCommentId(IdUtils.simpleUUID());
        }
        itemsCommentsRepository.saveComments(userId, commentList);
        // 2. 修改订单表改已评价
        orderClient.updateCommentsStatus(orderId);
        // 3. 修改订单状态表的留言时间 order_status
        orderClient.updateOrderStatus(orderId);
    }

    /**
     * 查询我的评论.
     *
     * @param userId   用户id
     * @return 我的评论分页信息
     */
    public PagedGridResult<MyCommentBo> queryMyComments(String userId, Integer page, Integer pageSize) {
        return itemsCommentsRepository.queryMyComments(userId, page, pageSize);
    }
}
